#ifndef MOCKSERVERHANDLER_H
#define MOCKSERVERHANDLER_H

#include <QThread>
#include <QSharedPointer>
#include <QTcpSocket>
#include <QTest>
#include <QHostAddress>
#include <string>
#include <iostream>

#include "wireformat.h"
#include "payload.h"
#include "anyevent.h"
#include "qslog.h"
#include "entity/oms.pb.h"

class MockServerHandler : public QThread
{
	Q_OBJECT

public:
	MockServerHandler(int socketDescriptor, QObject *parent = NULL);
	~MockServerHandler();
	void write(char* data, int size);
	void stop(){stopped = true; exit();}
signals:
	void error(QString ip, int port, QTcpSocket::SocketError socketError);
	void finishedThread(QThread *thread);
protected:
    virtual void run();
	virtual void customEvent(QEvent *event);
public slots:
	void read();
	void error2(QAbstractSocket::SocketError socketError);
	void onSendMessage();
private:
	QSharedPointer<QTcpSocket> socket;
	int socketDescriptor;
	volatile bool stopped;

	apollo::core::WireFormat format;
	apollo::core::WireFormat::ReadingContext ctx;
	

};

#endif // MOCKSERVERHANDLER_H
